﻿using System;
using Gqq.Library.Delegate;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Gqq.UnitTest
{
    [TestClass]
    public class LibraryTest
    {
        [TestMethod]
        public void TestDelegate()
        {
            //匿名委托
            GetStringHandler toString = (a, b) => (a + b).ToString();
            var str = toString(3, 4);
            Assert.AreEqual(7.ToString(), str);
            //            Assert.Inconclusive("test");

            //如何很好的使用泛型委托，是灰常重要的。
            ConvertHandler<string, int?> ch = delegate(string x)
                {
                    int outX;
                    if (Int32.TryParse(x, out outX))
                    {
                        return outX;
                    }
                    return null;
                };
            Assert.AreEqual(3, ch("3"));
            Assert.IsNull(ch("str"));
            Assert.IsNull(ch("934324234324324"));
        }
    }
}
